home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
DBCOMPRS.C
< prev
next >
Wrap
Text File
|
1985-10-26
|
3KB
|
120 lines
/*
* Program to read a dBASE program file and produce a copy of it
* from which the comment lines have been discarded and in which
* leading spaces before program lines have also been discarded.
*/
#include "stdio.h"
#define CR 0xd
#define LF 0xa
#define TB 0x9
#define SP 0x20
#define TRUE 1
#define FALSE 0
main(argc,argv)
int argc;
char *argv[];
{
char buffer[256];
int c,
comment,
buffposn,
eofinp,
outfile,
infile;
if ((argc == 1) || (argv[1][0] == '?'))
{
puts("\n");
puts("Syntax: DBCOMPRS <infile> <outfile>\n");
puts("where infile is the filespec for the input data\n");
puts(" outfile is the filespec for the output data\n");
puts("\n");
puts("The input file is assumed to be a dBASE .PRG file.\n");
puts("\n");
puts("The output file is merely a copy of the input file with the\n");
puts("comment lines and leading spaces before code lines stripped\n");
puts("from it .\n");
puts("\n");
exit(0);
}
if (argv[1][0] == '#')
{
puts("\n");
puts("PROGRAM: DBCOMPRS\n");
puts("Author : Peter Townsend\n");
puts("Date : 25Oct85\n");
puts("Version: 1.0\n");
exit(0);
}
if ((infile = open(argv[1],0)) == -1)
{
printf("\nCannot open input file %s\n",argv[1]);
exit(1);
}
if (argc == 2)
{
printf("\nMissing Output Filename\n");
exit(1);
}
if (strcmp(argv[1],argv[2]) == 0)
{
printf("\nInput filename and output filename cannot be the same.\n");
exit(1);
}
if ((outfile = open(argv[2],1)) == -1)
{
if ((outfile = creat(argv[2])) == -1)
{
printf("\nCannot create output file %s\n",argv[2]);
exit(1);
}
}
eofinp = FALSE;
while (!eofinp)
{
/*
* Read a line into the buffer
*/
buffposn = 0;
c = fgetc(infile);
eofinp = (c == EOF);
while ((c != LF) && (!eofinp))
{
buffer[buffposn++] = c;
c = fgetc(infile);
eofinp = (c == EOF);
}
if (c == LF)
{
buffer[buffposn++] = c;
}
/*
* Make the buffer a string by terminating it with a null
*/
buffer[buffposn] = '\0';
/*
* Step along the string until a non-blank or -tab is
* encountered or until end of string
*/
buffposn = 0;
c = buffer[buffposn];
while ((c == SP) || (c == TB))
{
c = buffer[++buffposn];
}
comment = (c == '*');
/*
* If the line isn't a comment, output it
*/
if (!comment)
{
while(buffer[buffposn] != '\0')
{
putc(buffer[buffposn++],outfile);
}
}
}
fclose(infile);
fclose(outfile);
exit(0);
}